package me.chan.completableFuture;

import java.util.concurrent.Future;
import static me.chan.completableFuture.Util.delay;

public class Client {

	public static void main(String[] args) {
		AsyncShop shop = new AsyncShop("Best SHOP");
		long start = System.nanoTime();
		Future<Double> futurePrice = shop.getPriceAsync("my favorite product");
		long invocationTime = (System.nanoTime() - start) / 1_000_000 ;
		System.out.println("Invocation returned after" + invocationTime + "msecs");
		doSomethingElse();
		try {
			double price = futurePrice.get();
			System.out.printf("the product is %.2f%n", price);
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
		long retrievalTime = (System.nanoTime() - start ) / 1_000_000;
		System.out.println("Price returned after" + retrievalTime + "msecs");
		
	}

	private static void doSomethingElse() {
		delay();
	}
}
